package com.huawei.hwid.core.b.a.a;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.cloudservice.CloudRequestHandler;
import com.huawei.hms.framework.common.ContainerUtils;
import com.huawei.hwid.core.b.a.a.c;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.core.datatype.HwAccount;
import com.huawei.hwid.core.helper.handler.ErrorStatus;
import java.io.IOException;
import java.util.HashMap;
import o.avg;
import org.xmlpull.v1.XmlPullParserException;

public class g extends com.huawei.hwid.core.b.a.a {
    private String h;
    private String i;
    private String j = "com.huawei.hwid";
    private String k;
    private int l = 7;
    private String m;
    private String n;
    private String o;
    private String p;
    private int q;
    private String r;
    private String s = "/IUserPwdMng/uidVerifyPassword";
    private String t = this.s;
    private String u;
    private String v;
    private String w;
    private Context x;

    public static class a {
        public String a = "";
        public String b = "";
        private boolean c = false;

        public a(String str) {
            if (!TextUtils.isEmpty(str)) {
                int lastIndexOf = str.lastIndexOf("&resultDigest=");
                if (lastIndexOf != -1) {
                    this.a = str.substring(0, lastIndexOf);
                    this.b = str.substring(lastIndexOf + "&resultDigest=".length());
                    this.c = true;
                }
            }
        }

        public boolean a() {
            return this.c;
        }
    }

    static class b extends com.huawei.hwid.core.helper.handler.a {
        private CloudRequestHandler a;

        public b(Context context, CloudRequestHandler cloudRequestHandler) {
            super(context);
            this.a = cloudRequestHandler;
        }

        public void a(Bundle bundle) {
            super.a(bundle);
            this.a.onFinish(bundle);
        }

        public void b(Bundle bundle) {
            super.b(bundle);
            ErrorStatus errorStatus = (ErrorStatus) bundle.getParcelable("requestError");
            if (errorStatus != null) {
                this.a.onError(errorStatus);
            } else {
                this.a.onError(new ErrorStatus(32, "ErrorStatus is null"));
            }
        }
    }

    public g(Context context, String str, String str2, String str3, String str4, int i, String str5, String str6, String str7, int i2) {
        this.x = context;
        a(c.b);
        g(str3);
        if (!TextUtils.isEmpty(str2)) {
            f(str2);
        }
        h(str);
        if (i2 <= 0) {
            HwAccount b = com.huawei.hwid.d.a.a(context).b();
            if (b != null) {
                a(context, com.huawei.hwid.core.d.b.a(context, b.b()));
            }
        } else {
            a(context, i2);
        }
        i(str4);
        j(str5);
        k(str6);
        l(str7);
        b(70002003);
        b(70002058);
    }

    private void f(String str) {
        this.j = str;
    }

    public String j() throws IllegalArgumentException, IllegalStateException, IOException {
        return null;
    }

    public void a(String str) throws XmlPullParserException, IOException {
    }

    public String k() {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("ver=").append("27120").append(ContainerUtils.FIELD_DELIMITER).append("uid=").append(this.h).append(ContainerUtils.FIELD_DELIMITER).append("pw=").append(this.i).append(ContainerUtils.FIELD_DELIMITER).append("clT=").append(this.l).append(ContainerUtils.FIELD_DELIMITER).append("app=").append(this.j).append(ContainerUtils.FIELD_DELIMITER).append("dvT=").append(this.p).append(ContainerUtils.FIELD_DELIMITER).append("dvID=").append(this.n).append(ContainerUtils.FIELD_DELIMITER).append("fg=").append(this.k).append("&lang=").append(c(this.x));
        if (!TextUtils.isEmpty(this.o)) {
            stringBuffer.append(ContainerUtils.FIELD_DELIMITER).append("dvID2=").append(this.o);
        }
        this.u = avg.ˊ();
        stringBuffer.append("&salt=").append(this.u);
        if (HwAccountConstants.TYPE_SINA.equals(this.k)) {
            stringBuffer.append("&udid=").append(this.v).append("&hmac=").append(this.w);
        }
        return stringBuffer.toString();
    }

    public void b(String str) {
        if (!TextUtils.isEmpty(str)) {
            String[] split = str.split(ContainerUtils.FIELD_DELIMITER);
            HashMap hashMap = new HashMap();
            Object obj = "";
            for (String split2 : split) {
                String[] split3 = split2.split(ContainerUtils.KEY_VALUE_DELIMITER);
                hashMap.put(split3[0], split3[1]);
                obj = split3[0];
            }
            if (hashMap.containsKey("resultCode")) {
                this.b = com.huawei.hwid.f.g.a((String) hashMap.get("resultCode"));
            }
            if (this.b == 0) {
                this.r = (String) hashMap.get("userID");
                this.m = (String) hashMap.get("st");
                try {
                    this.q = Integer.parseInt((String) hashMap.get(HwAccountConstants.EXTRA_OPLOG_SITEID));
                } catch (Exception e) {
                    e.d("TGC", "pares siteId Exception", true);
                }
                if (!a(str, hashMap)) {
                    this.b = 70002003;
                    this.c = this.b;
                    this.d = "Failed to verify signature.";
                    e.d("UidVerifyPasswordRequest", "Failed to verify the digital signature of VerifyPassword response.", true);
                    return;
                }
                return;
            }
            this.c = this.b;
            this.d = (String) hashMap.get(obj);
        }
    }

    private boolean a(String str, HashMap<String, String> hashMap) {
        if (hashMap.containsKey("salt")) {
            String str2 = (String) hashMap.get("salt");
            if (this.u != null && this.u.equals(str2)) {
                a aVar = new a(str);
                if (aVar.a() && avg.ˏ(aVar.a, aVar.b, "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp/+96hx/XKdWBKS6yh14vERYLhg84G52FNXS1YKEll0VFdMHAVWRZlOLguYptqd+1LZePWvgXUEXws+/ibetjhBWG0n85UyhSC8r0g4/gRTQcNna0HbPRx9WMS2XkMWD33T24BZSuEnPOBjOwJrHCVnJDqZVrw3g+gfYygXo1KVJOM0VRA97zbQxsLQIZhTj7DUG5ySj5ltrPVmpLydppYQxp+JUG2vwo2ifqYvcPzVjRcw44rK1gT6d+DHeziw7ZmnOwog2uUyDULNbMWc1e4RFYssRS8yV2vSJNyTKwZw5IdfPBBCpoX9M7Fp6ivUkZVEtVJQHXcompv37KxoUVwIDAQAB")) {
                    return true;
                }
            }
        }
        return false;
    }

    private void g(String str) {
        this.i = str;
    }

    private void h(String str) {
        this.h = str;
    }

    private void i(String str) {
        this.k = str;
    }

    private void j(String str) {
        this.n = str;
    }

    private void k(String str) {
        this.p = str;
    }

    private void l(String str) {
        this.o = str;
    }

    public String b() {
        return this.t;
    }

    public Bundle c() {
        Bundle c = super.c();
        c.putString("serviceToken", this.m);
        c.putString("userID", this.r);
        c.putInt(HwAccountConstants.EXTRA_OPLOG_SITEID, this.q);
        return c;
    }

    public String c(Context context) {
        return com.huawei.hwid.core.d.b.f(context);
    }

    public void a(Context context, com.huawei.hwid.core.b.a.a aVar, String str, CloudRequestHandler cloudRequestHandler) {
        com.huawei.hwid.core.b.a.e.a(context, aVar, str, a(context, aVar, new b(context, cloudRequestHandler)));
    }
}
